package com.aps.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.aps.entity.domain.dish.Dish;
import com.aps.entity.domain.order.OrderDish;
import com.aps.entity.domain.order.UnChargeDish;
import com.aps.service.IUnChargeService;
import com.aps.service.rep.DishRep;
import com.aps.service.rep.UnChargeDishRep;
import com.aps.util.DateUtil;

/**
 * @author liaoguangan
 * @description <>
 * @date 2018/4/1 16:46
 */
@Service
public class UnChargeServiceImpl implements IUnChargeService {

    @Autowired
    private UnChargeDishRep unChargeDishRep;

    @Autowired
    private DishRep dishRep;

    /**
     * 添加待分配队列
     * @param orderDish
     */
    @Override
    public void add(OrderDish orderDish) {
        UnChargeDish unChargeDish = new UnChargeDish();
        unChargeDish.setOrderDishId(orderDish.getId());
        unChargeDish.setCharge(false);

        //设置过期时间
        Dish dish = dishRep.findByCode(orderDish.getDishNum());
        Date expTime = DateUtil.addTime(dish.getExpTimeUnit(), dish.getExpTime().intValue());
        unChargeDish.setExpTime(expTime);

        unChargeDishRep.save(unChargeDish);
    }
}
